package cn.shengchao.wecom.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.shengchao.wecom.configure.WxCpConfiguration;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: examstarapi
 * @description: 企微辅助业务
 * @author: Xiong weiqiang
 * @create: 2025-04-22 09:38
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/wx/cp/help")
@SaIgnore
public class WxCpHelpController {
    @GetMapping("/{agentId}/getApiDomainIp")
    public String[] getApiDomainIp(
            @PathVariable Integer agentId) throws WxErrorException {
        final WxCpService wxCpService = WxCpConfiguration.getCpService(agentId);
        if (wxCpService == null) {
            throw new IllegalArgumentException(String.format("未找到对应agentId=[%d]的配置，请核实！", agentId));
        }
        String[] apiDomainIps = wxCpService.getApiDomainIp();
        return apiDomainIps;
    }
    @GetMapping("/{agentId}/getCallbackIp")
    public String[] getCallbackIp(
            @PathVariable Integer agentId) throws WxErrorException {
        final WxCpService wxCpService = WxCpConfiguration.getCpService(agentId);
        if (wxCpService == null) {
            throw new IllegalArgumentException(String.format("未找到对应agentId=[%d]的配置，请核实！", agentId));
        }
        String[] callbackIps = wxCpService.getCallbackIp();
        return callbackIps;
    }
}